package com.lyc.product.ServiceImpl;

import com.lyc.product.bean.Page;
import com.lyc.product.bean.Product;
import com.lyc.product.dao.ProductDao;
import com.lyc.product.daoIpml.ProductDaoImpl;
import com.lyc.product.service.ProductService;

import java.util.List;

public class ProductServiceImpl implements ProductService {
    ProductDao productDao=new ProductDaoImpl();

    /**
     * 获得首页商品的信息
     * @return
     */
    @Override
    public List<Product> getBookLisst() {
        List<Product> bookLisst = productDao.getBookLisst();
        return bookLisst;
    }

    /**
     * 根据指定的页数获取商品的信息(封装Page对象)
     * @param CurrentPageCount
     * @return
     */
    @Override
    public Page<Product> getBookListByPage(int CurrentPageCount) {
        //创建page对象
        Page<Product> productPage = new Page<Product>(CurrentPageCount);

        //获得当前查询条件下的总记录数
        int TotalRecordCount = productDao.getBookLisst().size();
        productPage.setTotalRecordCount(TotalRecordCount);
        //获取每页显示的内容
        List<Product> bookListByPage = productDao.getBookListByPage((productPage.getCurrentPageCount() - 1) * productPage.getPageRecordCount(),productPage.getPageRecordCount());
         productPage.setPageCotent(bookListByPage);

         //获取当前指定的页数
        productPage.setCurrentPageCount(CurrentPageCount);
        return productPage;
    }

    /**
     * 通过商品编号查询书籍
     * @param productId
     * @return
     */
    @Override
    public Product getBookByProductId(int productId) {
        Product bookByProductId = productDao.getBookByProductId(productId);
        return bookByProductId;
    }
}
